package com.example.shop.controller;

import java.util.List;
import java.util.concurrent.ExecutionException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.shop.pojo.Task;
import com.example.shop.pojo.UserDepartment;
import com.example.shop.service.TaskService;
import com.example.shop.utils.Result;

@RestController
@RequestMapping("/task")
public class TaskController {
	@Autowired
	private TaskService taskService;
	
	/**
	 * 添加任务1：任务名，任务详情
	 * 添加任务2：任务名，任务详情、任务部门
	 * 添加任务3：任务名，任务详情、任务人员
	 *  添加任务4：任务名，任务详情、任务部门、任务人员
	 */
	@PostMapping("/add/{account}")
	public Result<String> addTask(@PathVariable String account,@RequestBody List<Task> task){
		String result = taskService.addTask(task);
		if(!"任务添加成功".equals(result)) {
			return Result.fail(result);
		}
		return Result.success(result);
	}
	/**
	 * 任务更新 
	 */
	@PutMapping("/update/{account}")
	public Result<String> updateTask(@PathVariable String account,@RequestBody Task task){
		String result = taskService.updateTask(task);
		if(!"任务更新成功".equals(result)) {
			return Result.fail(result);
		}
		return Result.success(result);
	}
	/**
	 * 任务查询
	 */
	@GetMapping("/select/{account}")
	public Result<Task> selectTask(@PathVariable String account,@RequestBody Task task){
		
		List<Task> result = taskService.selectTask(task);
		if(result == null) {
			return Result.fail(result);
		}
		return Result.success(result);
	}
	/**
	 * 任务提醒
	 * @throws ExecutionException 
	 * @throws InterruptedException 
	 */
	@PutMapping("/remind/{account}")
	public Result<String> EventSetting(@PathVariable("account") String account,@RequestBody Task task) throws InterruptedException, ExecutionException{
		String result = taskService.EventSetting(task);
		if(!"事件设置成功".equals(result)) {
			return Result.fail(result);
		}
		return Result.success(result);
	}

}
